<style>
    input[type='checkbox'] { width:20px;height:20px; }
</style>
<script type="text/javascript">
    //尺寸颜色
    function modifySize(){
        var id = $('#id').val();
        console.log(id);
        var formData = {
            id:id
        };
        $.ajaxSetup({
            headers: { 'X-CSRF-TOKEN': $('#_token').val() }
        });
        $.ajax({
            type:'post',
            url:getPrefix() + '/size-get',
            data:formData,
            success:function(res){
                //console.log(res); return
                if (res.code!=0) {
                    console.log(res); return
                }
                var sizelistArr = res.data.sizelists;
                var colorArr = res.data.colors;
                console.log(sizelistArr,colorArr);
                var i, i2, h = '';
                h += '<table class="am-table am-table-striped am-table-hover table-main">';
                h += '<tr>';
                h += '<td><b></b></td>';
                h += '<td><b>S</b></td>';
                h += '<td><b>M</b></td>';
                h += '<td><b>L</b></td>';
                h += '<td><b>XL</b></td>';
                h += '<td><b>XXL</b></td>';
                h += '<td><b>XXXL</b></td>';
                h += '</tr>';
                for (i=0;i<sizelistArr.length;i++) {
                    h += '<tr>';
                    h += '<td><b>';
                    h += colorArr[i];
                    h += '<input type="hidden" name="color'+i+'" value="'+i+'">';
                    h += '</b></td>';
                    var sizes = sizelistArr[i];
                    for (i2=1;i2<sizes.length;i2++) {
                        h += '<td>';
                        h += '<input type="checkbox" name="size'+i+'-'+i2+'[]" ';
                        if (sizes.length>0 && sizes[i2]) {
                            h += ' checked ';
                        }
                        h += ' value="1" >';
                        h += '</td>';
                    }
                    h += '</tr>';
                }
                h += '</table>';
                h += '<hr>';
                $('#sizeTable').html(h);
                $('#sizeModify').modal();
            },
            error:function(){
                console.log('操作失败！');
            }
        });
    }
    //图片编辑
    function modifyImg(fileId){
        var nameArr = [
            '', '主图', '款式图', '粘衬部位', '背面图',
            '关键部位细节', '关键部位细节'
        ];
        var name = nameArr[fileId];
        $('input[name="key"]')[0].value = fileId;
        $('#imgName').html(name);
        $('#imgModify').modal();
    }
    //成分缩率编辑
    function modifyStuff(){
        var id = $('#id').val();
        var formData = {
            id:id
        };
        $.ajaxSetup({
            headers: { 'X-CSRF-TOKEN': $('#_token').val() }
        });
        $.ajax({
            type:'post',
            url:getPrefix() + '/stuff-get',
            data:formData,
            success:function(res){
                //console.log(res); return
                if (res.code!=0) {
                    console.log(res); return
                }
                var stuffArr = res.data;
                console.log(stuffArr);
                var i, h = '';
                h += '<input type="hidden" name="stuffCount" value="'+stuffArr.length+'">';
                h += '<table class="am-table am-table-striped am-table-hover table-main">';
                h += '<tr>';
                h += '<td><b>面辅料</b></td>';
                h += '<td><b>成分/缩率</b></td>';
                h += '</tr>';
                if (stuffArr.length > 0) {
                    for (i=0;i<stuffArr.length;i++) {
                        h += '<tr>';
                        h += '<td>';
                        h += '<input type="text" name="stuffKey'+i+'" value="'+stuffArr[i].key+'">';
                        h += '</td>';
                        h += '<td>';
                        h += '<input type="text" name="stuffVal'+i+'" value="'+stuffArr[i].val+'">';
                        h += '</td>';
                        h += '</tr>';
                    }
                }
                h += '<tr>';
                h += '<td colspan="2" style="text-align:center;">以下是新增的成分缩率</td>';
                h += '</tr>';
                h += '<tr>';
                h += '<td>';
                h += '<input type="text" name="stuffKey" placeholder="面辅料">';
                h += '</td>';
                h += '<td>';
                h += '<input type="text" name="stuffVal" placeholder="成分/缩率">';
                h += '</td>';
                h += '</tr>';
                h += '</table>';
                h += '<hr>';
                $('#stuffTable').html(h);
                $('#stuffModify').modal();
            },
            error:function(){
                console.log('操作失败！');
            }
        });
    }
    //面辅料单耗编辑
    function modifyDeplete(){
        var id = $('#id').val();
        var formData = {
            id:id
        };
        $.ajaxSetup({
            headers: { 'X-CSRF-TOKEN': $('#_token').val() }
        });
        $.ajax({
            type:'post',
            url:getPrefix() + '/deplete-get',
            data:formData,
            success:function(res){
                //console.log(res); return
                if (res.code!=0) {
                    console.log(res); return
                }
                var depleteArr = res.data;
                console.log(depleteArr);
                var i, h = '';
                h += '<input type="hidden" name="depleteCount" value="'+depleteArr.length+'">';
                h += '<table class="am-table am-table-striped am-table-hover table-main">';
                h += '<tr>';
                h += '<td><b>名称</b></td>';
                h += '<td><b>规格</b></td>';
                h += '<td><b>用量</b></td>';
                h += '<td><b>备注</b></td>';
                h += '</tr>';
                if (depleteArr.length > 0) {
                    for (i=0;i<depleteArr.length;i++) {
                        h += '<tr>';
                        h += '<td>';
                        h += '<input type="text" name="depleteName'+i+'" value="'+depleteArr[i].name+'">';
                        h += '</td>';
                        h += '<td>';
                        h += '<input type="text" name="depleteSize'+i+'" value="'+depleteArr[i].size+'">';
                        h += '</td>';
                        h += '<td>';
                        h += '<input type="text" name="depleteNum'+i+'" value="'+depleteArr[i].num+'">';
                        h += '</td>';
                        h += '<td>';
                        h += '<input type="text" name="depleteRemark'+i+'" value="'+depleteArr[i].remark+'">';
                        h += '</td>';
                        h += '</tr>';
                    }
                }
                h += '<tr>';
                h += '<td colspan="10" style="text-align:center;">以下是新增的单耗</td>';
                h += '</tr>';
                h += '<tr>';
                h += '<td>';
                h += '<input type="text" name="depleteName" placeholder="名称" minlength="1" maxlength="20">';
                h += '</td>';
                h += '<td>';
                h += '<input type="text" name="depleteSize" placeholder="规格/缩率" minlength="1" maxlength="20">';
                h += '</td>';
                h += '<td>';
                h += '<input type="text" name="depleteNum" placeholder="用量" pattern="\\d+">';
                h += '</td>';
                h += '<td>';
                h += '<input type="text" name="depleteRemark" placeholder="备注">';
                h += '</td>';
                h += '</tr>';
                h += '</table>';
                h += '<hr>';
                $('#depleteTable').html(h);
                $('#depleteModify').modal();
            },
            error:function(){
                console.log('操作失败！');
            }
        });
    }
    //产品种类编辑
    function modifyOrderType(){
        var id = $('#id').val();
        var formData = {
            id:id
        };
        $.ajaxSetup({
            headers: { 'X-CSRF-TOKEN': $('#_token').val() }
        });
        $.ajax({
            type:'post',
            url:getPrefix() + '/orderType-get',
            data:formData,
            success:function(res){
                //console.log(res); return
                if (res.code!=0) {
                    console.log(res); return
                }
                var orderTypeArr = res.data;
                console.log(orderTypeArr);
                var i, h = '';
                h += '<input type="hidden" name="orderTypeCount" value="'+orderTypeArr.length+'">';
                h += '<table class="am-table am-table-striped am-table-hover table-main">';
                h += '<tr>';
                h += '<td width="25%"><b>产品名称</b></td>';
                h += '<td><b>男装</b></td>';
                h += '<td><b>女装</b></td>';
                h += '<td><b>童装</b></td>';
                h += '</tr>';
                if (orderTypeArr.length > 0) {
                    for (i=0;i<orderTypeArr.length;i++) {
                        h += '<tr>';
                        h += '<td>';
                        h += '<input type="text" name="orderTypeName'+i+'" value="'+orderTypeArr[i].name+'">';
                        h += '</td>';
                        h += '<td><label>';
                        h += '<input type="checkbox" name="orderTypeMale'+i+'[]" value="1" ';
                        if (orderTypeArr[i].male==1) {
                            h += ' checked';
                        }
                        h += ' >';
                        h += '</label></td>';
                        h += '<td>';
                        h += '<input type="checkbox" name="orderTypeFemale'+i+'[]" value="1" ';
                        if (orderTypeArr[i].female==1) {
                            h += ' checked';
                        }
                        h += ' >';
                        h += '</td>';
                        h += '<td>';
                        h += '<input type="checkbox" name="orderTypeChild'+i+'[]" value="1" ';
                        if (orderTypeArr[i].child==1) {
                            h += ' checked';
                        }
                        h += ' >';
                        h += '</td>';
                        h += '</tr>';
                    }
                }
                h += '<tr>';
                h += '<td colspan="10" style="text-align:center;">以下是新增的单耗</td>';
                h += '</tr>';
                h += '<tr>';
                h += '<td>';
                h += '<input type="text" name="orderTypeName" placeholder="产品名称" minlength="1" maxlength="20">';
                h += '</td>';
                h += '<td><label>';
                h += '<input type="checkbox" name="orderTypeMale[]" value="1">';
                h += '</label></td>';
                h += '<td><label>';
                h += '<input type="checkbox" name="orderTypeFemale[]" value="1">';
                h += '</label></td>';
                h += '<td><label>';
                h += '<input type="checkbox" name="orderTypeChild[]" value="1">';
                h += '</label></td>';
                h += '</tr>';
                h += '</table>';
                h += '<hr>';
                $('#orderTypeTable').html(h);
                $('#orderTypeModify').modal();
            },
            error:function(){
                console.log('操作失败！');
            }
        });
    }
    //产品风格新增
    function addStyle(){
        $('input[name="styleOper"]')[0].value = 'add';
        $('#styleModify').modal();
    }
    //产品风格编辑
    function modifyStyle(styleId){
        $('input[name="styleOper"]')[0].value = 'modify';
        var name = $('#styleName'+styleId).val();
        $('input[name="styleKey"]')[0].value = styleId;
//        console.log(styleId,name); return
        $('input[name="styleName"]')[0].value = name;
        $('#styleModify').modal();
    }
    //产品款式新增
    function addDesign(){
        $('input[name="designOper"]')[0].value = 'add';
        $('#designModify').modal();
    }
    //产品款式编辑
    function modifyDesign(designId){
        $('input[name="designOper"]')[0].value = 'modify';
        var name = $('#designName'+designId).val();
        $('input[name="designKey"]')[0].value = designId;
//        console.log(designId,name); return
        $('input[name="designName"]')[0].value = name;
        $('#designModify').modal();
    }
    //请求地址
    function getPrefix(){
        return '/mcadmin/basic/order/bale/other';
    }
</script>